package com.example.crm.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.crm.dao.CustomerDAO;
import com.example.crm.pojo.Customer;

@WebServlet("/updatecustomer")
public class UpdateCustomerServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		// 设置提交过来的编码
		req.setCharacterEncoding("utf-8");
		
		
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter pw = resp.getWriter();
		
		// 1. 接收参数
		Customer c = new Customer();
		
		c.setId(Integer.parseInt(req.getParameter("id")));
		c.setName(req.getParameter("cust_name"));
		c.setSource(req.getParameter("cust_source"));
		c.setIndustry(req.getParameter("cust_industry"));
		c.setLevel(req.getParameter("cust_level"));
		c.setLinkman(req.getParameter("cust_linkman"));
		c.setPhone(req.getParameter("cust_phone"));
		c.setMobile(req.getParameter("cust_mobile"));
		
		// 2. 调用DAO
		// 2. 调用DAO
		CustomerDAO dao = new CustomerDAO();
		try {
			int result = dao.update(c);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		// 3. 跳转列表页面
		resp.sendRedirect("listcustomer");
		
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
